package com.zkca.xf.presenter;

import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.zkca.xf.base.BasePresenter;
import com.zkca.xf.manager.DataManager;
import com.zkca.xf.model.javabean.uploadbean.RequestPage;
import com.zkca.xf.view.FireAlarmLView;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DefaultObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by li on 2018/7/31.
 */

public class DianliuGPresenter extends BasePresenter {
    private DataManager dataManager;
    private FireAlarmLView smokeView;

    public DianliuGPresenter(LifecycleProvider<ActivityEvent> provider, FireAlarmLView smokeView) {
        super(provider);
        dataManager = DataManager.getInstance();
        this.smokeView=smokeView;
    }
    public void getDianG(RequestPage requestPage) {
        dataManager.getDianG(requestPage)
                .subscribeOn(Schedulers.io())// 在子线程中进行Http访问
                .observeOn(AndroidSchedulers.mainThread())// UI线程处理返回接口
                .compose(getProvider().<String>bindUntilEvent(ActivityEvent.DESTROY))// onDestroy取消订阅
                .subscribe(new DefaultObserver<String>() {// 订阅
                    @Override
                    public void onNext(String data) {
                        smokeView.getFireAlarm(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        smokeView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        smokeView.hideProgressDialog();
                    }
                });
    }
}
